package com.woniuxy.lab.woniu_lab_boss.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.lab.woniu_lab_boss.common.Result;
import com.woniuxy.lab.woniu_lab_boss.controller.form.LoginForm;
import com.woniuxy.lab.woniu_lab_boss.exception.WebException;
import com.woniuxy.lab.woniu_lab_boss.exception.WebExceptionCode;
import com.woniuxy.lab.woniu_lab_boss.model.Admin;
import com.woniuxy.lab.woniu_lab_boss.service.AdminService;
import com.woniuxy.lab.woniu_lab_boss.service.UserService;
import com.woniuxy.lab.woniu_lab_boss.service.dto.HealthDto;
import com.woniuxy.lab.woniu_lab_boss.service.dto.PlatformDto;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "[M]管理员相关接口")
@Slf4j
@Validated
public class AdminController {

    @Resource
    private UserService userService;

    @Resource
    private AdminService adminService;

    @ApiOperation("69 获取平台信息")
    @GetMapping("getPlatformInfo")
    public Result<PlatformDto> getPlatformInfo() {
//        log.info("获取平台信息");
        PlatformDto platformDto = adminService.getPlatformInfo();
        return Result.success(200, "SUCCESS", platformDto);
    }

    @ApiOperation("70 获取平台总收益")
    @GetMapping("getTotalIncome")
    public Result<BigDecimal> getTotalIncome() {
//        log.info("获取平台总收益");
        BigDecimal totalIncome = userService.getTotalIncome();
        return Result.success(200, "SUCCESS", totalIncome);
    }

    @ApiOperation("管理员修改密码")
    @GetMapping("modifyAdminPassword")
    public Result<Object> modifyPassword(@ApiParam(value = "原密码") @RequestParam String password,
                                         @ApiParam(value = "新密码") @RequestParam String newPassword) {
        log.info("管理员将{}密码修改{}", password, newPassword);
        Integer adminId = adminService.getAdminId();
        adminService.changePassword(adminId, password, newPassword);
        return Result.success(200, "SUCCESS", null);
    }
    @ApiOperation("新增管理员")
    @PostMapping("addAdmin")
    public Result<Object> addAdmin(@ApiParam(value = "新增管理员账号") @RequestParam String username ){
        log.info("新增管理员，账号为{}",username);
        adminService.addAdmin(username);
        return Result.success(200,"SUCCESS",null);
    }
}

